<template>
	<view class="">
		<view class="is-input has-pdlr-20">
			<text>持卡人姓名</text>
			<input type="text" @input="onInput_user" placeholder="请输入持卡人姓名" />
		</view>
		<view class="is-input has-pdlr-20">
			<text>银行卡账号</text>
			<input type="number" @input="onInput_no" placeholder="请输入银行卡账号" />
		</view>
		<view class="is-input has-pdlr-20">
			<text>银行名称</text>
			<picker @change="bindPickerChange" :value="index" :range="bank">
				<view class="uni-input">{{bank[index]}}</view>
			</picker>
		</view>
		<view class="is-input has-pdlr-20">
			<text>支行名称</text>
			<input type="text" @input="onInput_cmp" placeholder="请输入支行名称" />
		</view>
		<view class="is-input has-pdlr-20">
			<text>短信手机</text>
			<input type="text" @input="onInput_tel" placeholder="请输入接收银行短信的手机号" />
		</view>
		<view class="is-input has-pdlr-20">
			<text>备注信息</text>
			<input type="text" @input="onInput_memo" placeholder="请输入备注" />
		</view>
		<view class="has-pd-20">
			<button type="primary" @tap="bankup">提交</button>
		</view>
	</view>
</template>

<script>
	var _self;
	export default {
	    data() {
	        return {
				foxtel:'',
	            title: 'picker',
	            bank: [],
	            index: 0,
				bank_name:'',
				bank_no:'',
				bank_user:'',
				bank_cmp:'',
				bank_tel:'',
				bank_memo:'',
				userinfo:[],
				user_card_rz:0			
			}
		},
		onLoad(){
			this.bank = this.service.FOX_BANK_LIST;
			this.bank_name = this.bank[this.index];
			_self = this;
			let info = this.service.getfox();
			if(info[0]){
				this.foxtoken = info[0]['foxtoken'];
				uni.request({
					url: this.service.FOX_URL + 'diamond/get_userinfo',
					method:'POST',
					data: {
						user_key: this.foxtoken
					},
					dataType:'json',
					header:{
						'content-type':'application/x-www-form-urlencoded',
					},
					success: res => {
						// var rest = JSON.stringify(res);
						// console.log(res)
						var rest = res.data;
						if(rest.status == 'success'){
							this.userinfo = rest.msg;
							this.user_card_rz = this.userinfo['user_card_rz']
							// console.log(this.userinfo)
						}else{
							uni.showToast({
								title:rest.msg,
								icon:'none',
								mask:true
							})
						}
					}
				})
			}else{
				uni.reLaunch({
					url:'../logon/login'
				})
			}
		},
		methods: {
			bindPickerChange: function(e) {
				this.index = e.target.value
				this.bank_name = this.bank[this.index]
			},
			onInput_user(e) {
				this.bank_user = e.detail.value;
			},
			onInput_no(e) {
				this.bank_no = e.detail.value;
				// console.log(this.service.checkBank(this.bank_no))
			},
			onInput_cmp(e) {
				this.bank_cmp = e.detail.value;
			},
			onInput_tel(e) {
				this.bank_tel = e.detail.value;
			},
			onInput_memo(e) {
				this.bank_memo = e.detail.value;
			},
			bankup(){
				if(this.service.checkuname(this.bank_user) === false){
					uni.showToast({
						title:'持卡人姓名错误',
						icon:'none',
					})
					return;
				}
				if(this.service.checkBank(this.bank_no) === false){
					uni.showToast({
						title:'银行卡账号错误',
						icon:'none',
					})
					return;
				}
				if(this.bank_name.length <= 0){
					uni.showToast({
						title:'银行名称错误',
						icon:'none',
					})
					return;
				}
				if(this.bank_cmp.length > 20 || this.bank_cmp.length <= 0){
					uni.showToast({
						title:'支行名称错误',
						icon:'none',
					})
					return;
				}
				if(this.service.checkphone(this.bank_tel) === false){
					uni.showToast({
						title:'短信通知手机错误',
						icon:'none',
					})
					return;
				}
				let info = this.service.getfox();
				if(info[0]){
					var foxtoken = info[0]['foxtoken'];
					var foxtel = info[0]['foxtel'];
					uni.request({
						url:this.service.FOX_URL+'diamond/addbank',
						method:'POST',
						data: {
							user_key: foxtoken,
							user_tel: foxtel,
							bank_user: this.bank_user,
							bank_name: this.bank_name,
							bank_no: this.bank_no,
							bank_tel:this.bank_tel,
							bank_cmp:this.bank_cmp,
							bank_memo:this.bank_memo
						},
						dataType:'json',
						header:{
							'content-type':'application/x-www-form-urlencoded',
						},
						success: res => {
							var rest = res.data;
							if(rest.status == 'error'){
								uni.showToast({
									title:rest.msg,
									icon:'none',
									mask:true
								})
							}else if(rest.status == 'success'){
								uni.navigateBack();
							}
						}
					})
				}
			}
		}
	}
</script>

<style>
	.is-input{
		background: #FFFFFF;
		height: 88rpx;
		line-height: 88rpx;
		margin-bottom: 20rpx;
	}
	.is-input text{		
		float: left;
		margin-right: 10rpx;
		color: #222;
	}
	.is-input input{
		display: inline-block;
		height: 88rpx;
		line-height: 88rpx;
	}
</style>
